package org.example.tliaswebmanagement.mapper;

import org.apache.ibatis.annotations.*;
import org.example.tliaswebmanagement.pojo.Emp;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理
 */
@Mapper
public interface EmpMapper {
    /**
     * 查询总记录数
     * @return
     */
//    @Select("select count(1) from emp")
//    public Long count();

    /**
     * 分页查询，获取列表数据
     * @param start
     * @param pageSize
     * @return
     */
//    @Select("select id,username,password,name,gender,image,job,entrydate,dept_id,create_time,update_time from emp limit #{start},#{pageSize}")
//    public List<Emp> page(@Param("start") Integer start, @Param("pageSize") Integer pageSize);

    /**
     * 员工信息查询
     * @return
     */
 //   @Select("select id,username,password,name,gender,image,job,entrydate,dept_id,create_time,update_time from emp")
    public List<Emp> list(@Param("name") String name, @Param("gender") Short gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);

    /**
     * 批量删除
     * @param ids
     */
    void delete(List<Integer> ids);

    /**
     * 新增员工
     * @param emp
     */
    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "values(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    @Select("select id,username,password,name,gender,image,job,entrydate,dept_id,create_time,update_time from emp where id = #{id}")
    Emp selectById(Integer id);

    void update(Emp emp);

    /**
     * 根据用户名与密码查询员工
     * @param emp
     * @return
     */
    @Select("select id,username,password,name,gender,image,job,entrydate,dept_id,create_time,update_time from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPwd(Emp emp);

    /**
     * 根据部门ID删除该部门下的员工数据
     * @param deptId
     */
    @Delete("delete from emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);
}
